Fix NativeAOT assembly name mangling collisions#130012
Fix NativeAOT assembly name mangling collisions#130012MichalStrehovsky with Copilot wants to merge 9 commits into
Conversation
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
Addressed the review feedback in b4734ac89: the mangler now keys by EcmaAssembly, and the unit test was replaced with an end-to-end NativeAOT test under src/tests. |
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
2026-06-30T09:09:11.7112339Z CSC : warning CS2008: No source files specified. [/__w/1/s/src/tests/nativeaot/SmokeTests/AssemblyNameCollision/AssemblyWithDot/AssemblyWithDot.csproj] [/__w/1/s/src/tests/build.proj] Also move the test out of SmokeTests to a src/tests/nativeaot/Regressions directory. Rename AssemblyNameCollision to Runtime112629. |
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Addressed in 849c26f: moved the test to |
Removed OutputType property from the project file.
There was a problem hiding this comment.
Pull request overview
This PR updates NativeAOT’s name mangling to avoid collisions when different assembly simple names sanitize to the same C identifier, and adds a regression test scenario with colliding assembly names.
Changes:
- Add cached, deterministic mangling for assembly-name prefixes to avoid sanitized-name collisions across input/reference assemblies.
- Update type-name mangling to use the new mangled assembly prefix.
- Add a NativeAOT regression test that references two assemblies whose names collide when sanitized (
A.BvsA_B).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs | Adds deterministic disambiguation/caching for mangled assembly prefixes and uses it when building mangled type names. |
| src/tests/nativeaot/Regressions/Runtime112629/Runtime112629.csproj | Adds a new NativeAOT regression test project referencing two colliding-name assemblies. |
| src/tests/nativeaot/Regressions/Runtime112629/Runtime112629.cs | Implements the regression scenario that exercises two assemblies whose names sanitize to the same identifier. |
| src/tests/nativeaot/Regressions/Runtime112629/AssemblyWithDot/AssemblyWithDot.csproj | Adds helper library project with assembly name A.B. |
| src/tests/nativeaot/Regressions/Runtime112629/AssemblyWithDot/TestType.cs | Defines a simple type to validate correct binding to A.B. |
| src/tests/nativeaot/Regressions/Runtime112629/AssemblyWithUnderscore/AssemblyWithUnderscore.csproj | Adds helper library project with assembly name A_B. |
| src/tests/nativeaot/Regressions/Runtime112629/AssemblyWithUnderscore/TestType.cs | Defines a simple type to validate correct binding to A_B. |
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>0</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Runtime112629.cs" /> | ||
| <ProjectReference Include="AssemblyWithDot\AssemblyWithDot.csproj" Aliases="AssemblyWithDot" /> | ||
| <ProjectReference Include="AssemblyWithUnderscore\AssemblyWithUnderscore.csproj" Aliases="AssemblyWithUnderscore" /> | ||
| </ItemGroup> | ||
| </Project> |
| static bool IsSystemPrivateAssemblyName(string assemblyName) | ||
| { | ||
| return assemblyName.StartsWith("System.Private.", StringComparison.Ordinal); | ||
| } |
| private Utf8String GetMangledAssemblyName(EcmaAssembly assembly) | ||
| { | ||
| string assemblyName = assembly.GetName().Name; | ||
| lock (this) | ||
| { | ||
| if (_mangledAssemblyNames.TryGetValue(assemblyName, out Utf8String mangledName)) | ||
| return mangledName; | ||
|
|
||
| return ComputeMangledAssemblyName(assemblyName, (CompilerTypeSystemContext)assembly.Context); |
Summary of changes
NativeAOT could generate duplicate mangled type names when different assembly names sanitized to the same C identifier, causing ILCompiler to fail with a duplicate-key exception.
System.Private.*assembly names.System.Private.*→S.P.*mangling without disambiguation.src/testswith colliding assembly names (A.BandA_B).Validation
./build.sh clr+libs+host./build.sh clr+libs+host./build.sh clr.aot+libs -rc Release -lc Releasesrc/tests/build.sh -nativeaot -test:nativeaot/SmokeTests/AssemblyNameCollision/AssemblyNameCollision.csproj x64 releaseartifacts/tests/coreclr/linux.x64.Release/nativeaot/SmokeTests/AssemblyNameCollision/AssemblyNameCollision.shPR Checklist
Issues in this repository are used to track work and discussions. Please create or link to an issue.